import Vue from 'vue'
import store from './store'
import App from './App'
import cuCustom from './components/cu-custom.vue'
import tabBar from './components/tabBar.vue' 
import fui from '@/uni_modules/ddiot-ui/js_sdk/index.js'
import diandi from './config.js'
import hxNavbar from './components/hx-navbar/hx-navbar.vue'
import uView from '@/uni_modules/uview-ui'
Vue.use(uView)
// import router from './router'
// import { RouterMount } from 'uni-simple-router'

// 引入uView
// import uView from 'uview-ui';
// Vue.use(uView);

import {
    router,
    RouterMount
} from './router.js' //路径换成自己的
Vue.use(router)

import UniSocket from "@/uni_modules/ddiot-ui/js_sdk/websocket/ddiot_websocket.js"

const socket = new UniSocket({
    url: "wss://iot.ddicms.cn:9501/",
    heartRateType: 'heart',
    heartRate: 60000,
    username: 'haode1',
    password: '12345678',
    AppKey: 'Y1NZAM9WK8OSQJCX70NRBVG6AL4FJPUW',
    AppSecret: 'IXLVB1PQPRT2MFNOW5DE0ZSHRYXJAQDG'
})

// #ifdef H5
window.QQmap = null;
// #endif
// #ifndef MP-TOUTIAO
//网络监听
setTimeout(() => {
    uni.onNetworkStatusChange(function(res) {
        //console.log(res.networkType);
        store.commit("networkChange", {
            isConnected: res.isConnected
        })
    });
}, 100)
// #endif
Vue.prototype.fui = fui
Vue.prototype.UniSocket = socket
Vue.prototype.$eventHub = Vue.prototype.$eventHub || new Vue()
Vue.prototype.$store = store
Vue.component('tab-bar', tabBar)
Vue.component('cu-custom', cuCustom) //全局导航组件
Vue.component('hx-navbar', hxNavbar) //全局navbar组件
Vue.prototype.iGlobal = fui.iglobal //将global.js挂载至Vue.prototype 实现全局调用
Vue.prototype.$store = store
Vue.config.productionTip = false

App.mpType = 'app'


Vue.use(fui, {
    // 请求相关的配置
    http: {
        // 请求头字段配置（baseURL无效），设置请求地址请在下面的apiConfig里面进行配置
        header: {
            'bloc-id': diandi.bloc_id,
            'store-id': diandi.store_id,
            // 'access-token':uni.getStorageSync('access_token')
        },
        successCode: 200,
		ddiot:{
			'bloc_id': diandi.bloc_id,
			'store_id': diandi.store_id,
		},
        apiConfig: {
            // 代理名称
            proxyName: 'https://hotelapi.ddicms.cn/api',
            // proxyName: 'http://www.ddiot-local.com/api',
            tokenApi: '/wechat/basics/signup',
            refreshApi: '/user/refresh',
            // 备用域名配置,至少配置一个,这边会自动设置baseUrl，至少传入一个域名，H5本地调试会自己代理到proxyName
            domain: diandi.baseUrl
        },
        responseSuccessCallBack: (res, catchObj, query) => {
            // console.log('请求触发1', res, catchObj, query);
            if (res.code === 403) {
                console.log('请求触发1--403');
                uni.removeStorageSync('access_token');
                fui.toLogin(403)
            }
        }
    }
})

const app = new Vue({
    store,
    ...App
})

//v1.3.5起 H5端 你应该去除原有的app.$mount();使用路由自带的渲染方式
// #ifdef H5
RouterMount(app, router, '#app')
// #endif

// #ifndef H5
app.$mount(); //为了兼容小程序及app端必须这样写才有效果
// #endif